<template>
	<view class="home">
		<view class="list">
			<view class="item" v-for="(item, index) in tabsList" :key="index" @click="handleClick(index)">
				<view class="count">
					{{item.count}}
					<!-- <view v-if="item.new">
						<u-badge type="error" :is-center="true" :count="item.new"></u-badge>
					</view> -->
				</view>
				<view class="name">
					{{item.name}}
				</view>
				<view class="line" :class="current == index ? 'active' : ''"></view>
			</view>
		</view>
		<!-- 待评论列表 -->
		<view class="pilicy-list">
			<pilicy-list :list="data" @click="toBacklogDclareDetail"></pilicy-list>
		</view>
	</view>
</template>

<script>
	import PilicyList from '@/components/pilicy-list/PilicyList.vue';
	import {
		apiGetAppealByUserL
	} from '@/api/publicity/publicity.js';
	import {
		apiGetInformations
	} from '@/api/home/home.js'
	export default {
		name: 'Home',
		components: {
			PilicyList
		},
		data() {
			return {
				current: 0,
				tabsList: [{
						count: 0,
						name: '待办事项',
						new: 7
					},{
						count: 0,
						name: '已办事项',
						new: 7
					},
					{
						count: 0,
						name: '已公示',
						new: 7
					},
					{
						count: 0,
						name: '我的评论',
					},
				],
				data: [],
				currentType: 0
			}
		},
		created() {
			uni.$on('updateData', () => {
				this.apiGetInformations();
				this.apiGetAppealByUserL(this.currentType);
			})
			this.handleClick(this.current);
			this.apiGetInformations();
			// this.apiGetAppealByUserL(4);
		},
		methods: {
			handleClick(index) {
				this.current = index;
				switch (index) {
					case 0:
						this.currentType = 4;
						this.apiGetAppealByUserL(4);
						break;
					case 1:
					this.currentType = 2;
					this.apiGetAppealByUserL(2);
						
						break;
					case 2:
					this.currentType = 1;
					this.apiGetAppealByUserL(1);
					break;
					case 3:
					this.currentType = 3;
					this.apiGetAppealByUserL(3);
						
					default:
						break
				}
			},
			//跳转代办事项详情
			toBacklogDclareDetail(info) {
				console.log(info)
				this.$Router.push({
					name: 'backlog_declare_detail',
					params: {
						id: info.appeal_id
					}
				});
			},
			async apiGetAppealByUserL(type) {
				const res = await apiGetAppealByUserL(type);
				this.data = res.data.list;
				console.log(this.data)
				console.log(res)
			},
			//获取代办 - 处理中 数量
			async apiGetInformations() {
				const res = await apiGetInformations();
				this.tabsList[0].count = res.data.daiban_num;
				this.tabsList[1].count = res.data.weigongshi_num;
				this.tabsList[2].count = res.data.yigongshi_num;
				this.tabsList[3].count = res.data.yipinglun_num;
			},
		},
		beforeDestroy() {
			uni.$off('updateData')
		}
	}
</script>

<style lang="scss" scoped>
	.home {
		margin-top: 30rpx;
		width: 710rpx;
		// height: 1078rpx;
		background: #FFFFFF;
		border-radius: 20rpx;

		.list {
			display: flex;
			justify-content: space-around;
			padding: 30rpx;
			padding-bottom: 0;
			border-bottom: 1px solid #E5E5E5;
			margin: 0 -20rpx;

			.item {
				text-align: center;

				.count {
					position: relative;
					font-size: 60rpx;
					font-family: D-DIN;
					font-weight: bold;
					color: #000000;
				}

				.name {
					margin-top: 10rpx;
					font-size: 26rpx;
					color: #000000;
				}

				.line {
					margin-top: 10rpx;
					width: 130rpx;
					height: 16rpx;
					background: transparent;
					border-radius: 10rpx 10rpx 0rpx 0rpx;

					&.active {
						background-color: #196EFF;
					}
				}
			}
		}
	}

	::v-deep.pilicy-list {
		padding-left: 0;
		width: 690rpx;
	}
</style>
